package com.lulufind.lulu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.lulufind.lulu.model.Banner;
import com.lulufind.lulu.model.Post;
import com.lulufind.lulu.model.Result;
import com.lulufind.lulu.model.Tag;
import com.lulufind.lulu.service.AlbumService;
import com.lulufind.lulu.service.PostService;
import com.lulufind.lulu.vo.AlbumInfoVO;
import com.lulufind.lulu.vo.PostInfoVO;
import com.lulufind.lulu.vo.SearchInfoVO;

@Controller
@RequestMapping("/post")
public class PostController {

	@Autowired
	PostService postService;
	@Autowired
	AlbumService albumService;
	
	@ResponseBody
	@RequestMapping(value="/addPost",produces="application/json;charset=UTF-8")
	public String addPost(Post post, String userToken, Integer[] tagIds, Integer[] accessIds){
		
		Result<Post> rs = postService.addPost(post, userToken, tagIds, accessIds);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/delPost",produces="application/json;charset=UTF-8")
	public String delPost(Integer userId, String userToken, Integer postId){
		
		Result<String> rs = postService.delPost(userId, userToken, postId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/startPostWeeding",produces="application/json;charset=UTF-8")
	public String startPostWeeding(Post post, String userToken){
		
		Result<String> rs = postService.startPostWeeding(post, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/completePostWeeding",produces="application/json;charset=UTF-8")
	public String completePostWeeding(Integer userId, String userToken, Integer postId){
		
		Result<String> rs = postService.completePostWeeding(userId, userToken, postId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/completePost",produces="application/json;charset=UTF-8")
	public String completePost(Integer userId, String userToken, Integer postId){
		
		Result<String> rs = postService.completePost(userId, userToken, postId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/changePost",produces="application/json;charset=UTF-8")
	public String changePost(Post post, String userToken, Integer[] tagIds){
		
		Result<Post> rs = postService.changePost(post, userToken, tagIds);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getPostInfo",produces="application/json;charset=UTF-8")
	public String getPostInfo(Integer postId, Integer userId, String userToken){
		
		Result<PostInfoVO> rs = postService.getPostInfo(postId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getUserPostInfoList",produces="application/json;charset=UTF-8")
	public String getUserPostInfoList(int userId, int start, int num){
		
		Result<List<PostInfoVO>> rs = postService.getUserPostInfoList(userId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getUserFollowPostInfoList",produces="application/json;charset=UTF-8")
	public String getUserFollowPostInfoList(int userId, int start, int num){
		
		Result<List<PostInfoVO>> rs = postService.getUserFollowPostInfoList(userId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getHotAlbum",produces="application/json;charset=UTF-8")
	public String getAlbumList(int start, int num){
		
		Result<List<AlbumInfoVO>> rs = albumService.getHotAlbum(start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAlbumInfo",produces="application/json;charset=UTF-8")
	public String getAlbumInfo(int albumId){
		
		Result<AlbumInfoVO> rs = albumService.getAlbumInfo(albumId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAllSearchInfo",produces="application/json;charset=UTF-8")
	public String getAllSearchInfo(){
		
		Result<List<SearchInfoVO>> rs = postService.getAllSearchInfo();
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getHotTag",produces="application/json;charset=UTF-8")
	public String getHotTag(int start, int num){
		
		Result<List<Tag>> rs = postService.getHotTag(start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getHotPost",produces="application/json;charset=UTF-8")
	public String getHotPost(int start, int num){
		
		Result<List<PostInfoVO>> rs = postService.getHotPost(start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCommendTag",produces="application/json;charset=UTF-8")
	public String getCommendTag(Integer start, Integer num){
		
		Result<List<Tag>> rs = postService.getCommendTag(start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAllBanner",produces="application/json;charset=UTF-8")
	public String getAllBanner(){
		
		Result<List<Banner>> rs = postService.getAllBanner();
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
}
